package com.wsb;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name= req.getParameter("userName");
        System.out.println(name);
        String pwd= req.getParameter("userPwd");
        System.out.println(pwd);
        if("admin".equals(name)){
            if("123456".equals(pwd)){
                HttpSession session=req.getSession();
                session.setAttribute("username","文思博");
                resp.sendRedirect("home.jsp");
                return;

            }
        }
        resp.sendRedirect("login.jsp?error=1");
    }
}
